import json
from mailbox import Mailbox

from flask import Flask, render_template, request
from werkzeug.routing import BaseConverter

from apps.service.LoginService import LoginService
from apps.pojo.Entity import db
app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:lei200404@localhost:3306/flask'
with app.app_context():
    db.init_app(app)
    db.create_all()
    db.drop_all()


@app.route('/')
def tologin():
  return render_template('login.html')

@app.route('/login', methods=['POST'])
def dologin():
    param = request.form
    username=param.get('username')
    password=param.get('password')
    user = LoginService().login(username,password)
    if user:
        return render_template('index.html',user=user)
    else:
        return render_template('login.html',msg='用户名或密码错误')

@app.get('/index_v1')
def index_v1():
  name= 'admin'
  return render_template('index_v1.html')

@app.get('/index_v3')
def index_v3():
  name= 'admin'
  return render_template('index_v3.html')


if __name__ == '__main__':
    app.run()


